package Source;

import DAO.MySQLAccountDAO;
import Views.ViewMain;

/**
 * The model for createuser
 * @author Josh
 */
public class CreateUser {

    private MySQLAccountDAO databaseConnection = new MySQLAccountDAO();
    private String user;
    private String password;
    private String confirmPassword;
    private String firstName;
    private String lastName;
    private String address;

    /**
     * Takes the values that the user should have enterend in the view and puts them into local variables
     * @param user
     * @param pass
     * @param conPass
     * @param firstName
     * @param lastName
     * @param address
     */
    public void addDataToModel(String user, String pass, String conPass, String firstName, String lastName, String address) {
        this.user = user;
        this.password = pass;
        this.confirmPassword = conPass;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;

    }

    /**
     * Checks if any of the data gotten from the user isn't filled in
     * @return boolean
     */
    public boolean checkData() {
        if (!user.equals("") || !password.equals("") || !confirmPassword.equals("") || !firstName.equals("") || !lastName.equals("") || !address.equals("")) {
            if (password.equals(confirmPassword)) {
                if (databaseConnection.checkAvailability(user)) {
                    return true;
                }
            }
        }  
        return false;
    }

        /**
         * Commits the data to the database and checks its availability and password
         * @return boolean
         */
    public boolean commitData() {
        databaseConnection.registerUser(user, new String(password), firstName, lastName, address);
        return true;
    }

    /**
     * Logs the user in
     */
    public void login() {
        ViewMain.setOnlineUser(databaseConnection.validAccount(user, password));
    }

    /**
     * Setter method for variable address.
     * @param address
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * Setter method for varriable confirmPassword.
     * @param confirmPassword
     */
    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    /** 
     * Setter method for variable firstName.
     * @param firstName
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Setter method for variable lastName.
     * @param lastName
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Setter method for variable password
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * Setter method for variable user.
     * @param user
     */
    public void setUser(String user) {
        this.user = user;
    }
    
    
}

